import { computed } from 'vue'
import type { Rule } from 'ant-design-vue/es/form'

/**
 * 部门表单验证规则
 * @returns 部门表单字段验证规则
 */
export const useFormRules = () => {
  const { t } = useI18n()

  return computed<Record<string, Rule[]>>(() => ({
    name: [
      { required: true, message: t('dept.nameRequired'), trigger: 'blur' },
      { min: 2, max: 20, message: t('dept.nameLength'), trigger: 'blur' }
    ],
    parentId: [
      { required: true, message: t('dept.parentRequired'), trigger: 'change' }
    ],
    orderNum: [
      { required: true, message: t('dept.orderRequired'), trigger: 'blur' },
      { type: 'number', message: t('dept.orderNumber'), trigger: 'blur' }
    ],
    phone: [
      { pattern: /^1[3-9]\d{9}$/, message: t('dept.phoneFormat'), trigger: 'blur' }
    ],
    email: [
      { type: 'email', message: t('dept.emailFormat'), trigger: 'blur' }
    ]
  }))
} 